/**
 * Created by Administrator on 2018/6/15.
 */

function showProInfo() {
    // var proId = $("#proId").val();
    $$scope.proId = $$scope.bid.projId;
    probox($$scope, $CertusFormAjax);
}
$CertusJsonAjax.ajax("queryBidProcessTrace",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processs = res.data;
})
$CertusJsonAjax.ajax("bidBaseInfo",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){

    $$scope.bid =res.data;

    $$scope.bid.proName =res.data.projName;

    //初始化
    $CertusFormAjax.ajax("departmentUser",{projId:$$scope.bid.projId},function(res){
        //姓名 id
        $$scope.bid.principalName = res.data.userName;
        $$scope.bid.specifiedMan = res.data.userId;

    })
    //项目 编号
    $$scope.bid.proNumber = res.data.proNumber;
    //项目区域
    $$scope.bid.proArea = res.data.proArea;
    //客户 名称
    $$scope.bid.customName= res.data.customName;
    //项目 编号
    $$scope.precedenceSelect = [
        {name:"低",precedence:1},
        {name:"中",precedence:2},
        {name:"高",precedence:3}
    ]
    $$scope.bid.precedence = res.data.precedence+"";
    $$scope.bid.deadlineDate = res.data.deadLineDate;
    // $$scope.

    $$scope.bid.processInstanceId =  $CertusJsonAjax.getProInstanceId();
    $$scope.bid.stepInstanceId =  $CertusJsonAjax.getStepInstanceId();
    var picker1 = $('#datetimeid').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn'),
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if(result && !angular.isUndefined(result)){
            $$scope.bid.deadlineDate= result;
            $$scope.$apply();
        }
    });
    $CertusJsonAjax.ajax('oldBaseInfo', {
        "processInstanceId": $CertusJsonAjax.getProInstanceId(),
        "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
    }, function (res) {
        // $$scope.bid.opinionMsg = res.data.opinionMsg;
        $$scope.bid.oldOpinionMsg = res.data.oldOpinionMsg;
    })
});

$$scope.submit = function(){
    var regex = /[0-9a-zA-Z]*/g;
    if($$scope.bid.principalName && ""!=$$scope.bid.principalName){
        var numList = $$scope.bid.principalName.match(regex);
        if($$scope.bid.principalId){

            $$scope.bid.specifiedMan = $$scope.bid.principalId;
            if(certusValidateNotnull()){
                $CertusJsonAjax.ajax("bidSubmit",$$scope.bid,function(res){
                    history.back();
                })
            }
        }
    }else{
        layer.msg("请填写下级审批人");
    }
}
$$scope.getsssbbb = function(bb){
    if(bb == "starting"){
        return "正在进行中";
    }else if(bb == "denied"){
        return "否决";
    }else if(bb == "sentback"){
        return "被退";
    }else if(bb == "others"){
        return "关闭";
    }else if(bb == "completed"){
        return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
    return "待办";
}




// function addBid($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies,$routeParams){
//
//
//     $scope.bid = {};
//     //暂时 写死
//     $scope.bid.templateCode = "TBLC";
//
//
//
//
//     $scope.submitBid = function(){
//         CertusJsonAjax.ajax("bidCommit",this.bid,function(res){
//             history.back();
//         })
//     }
// }